<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>部门详情 - HRM系统</title>
    <link rel="stylesheet" th:href="@{/css/style.css}">
    <link rel="stylesheet" th:href="@{/css/department-view.css}">
</head>
<body>
<div class="dashboard">
    <header class="header">
        <div class="logo">HRM系统</div>
        <div class="user-info">
            <span th:text="${currentUser.realName}"></span>
            <span class="role-badge" th:text="${currentUser.roleId.roleName}"></span>
            <a href="/logout" class="logout-btn">退出</a>
        </div>
    </header>
    <main class="department-view-container">
        <!-- 返回按钮 -->
        <div class="back-container">
            <a th:href="@{/department}" class="btn btn-back">← 返回部门列表</a>
            <a th:href="@{/home}" class="btn btn-back">← 返回首页</a>
        </div>

        <!-- 页面标题 -->
        <div class="module-header">
            <h1 class="module-title">部门详细信息</h1>
            <div class="action-buttons" th:if="${roleIdValue lt 4}">
                <a th:href="@{/department/edit/{id}(id=${department.departmentID})}" class="btn btn-primary">编辑部门</a>
            </div>
        </div>

        <!-- 部门基本信息卡片 -->
        <div class="department-card">
            <!-- 基本信息区 -->
            <div class="info-section">
                <h2 class="section-title">基本信息</h2>
                <div class="info-grid">
                    <div class="info-item">
                        <span class="info-label">部门ID：</span>
                        <span class="info-value" th:text="${department.departmentID}"></span>
                    </div>
                    <div class="info-item">
                        <span class="info-label">部门名称：</span>
                        <span class="info-value" th:text="${department.departmentName}"></span>
                    </div>
                    <div class="info-item">
                        <span class="info-label">部门代码：</span>
                        <span class="info-value" th:text="${department.departmentCode}"></span>
                    </div>
                    <div class="info-item">
                        <span class="info-label">部门级别：</span>
                        <span class="info-value" th:text="${department.departmentLevel}"></span>
                    </div>
                    <div class="info-item">
                        <span class="info-label">在职人数：</span>
                        <span class="info-value" th:text="${department.employeeCount}"></span>
                    </div>
                    <div class="info-item">
                        <span class="info-label">状态：</span>
                        <span class="status-active" th:if="${department.status}">启用</span>
                        <span class="status-inactive" th:unless="${department.status}">禁用</span>
                    </div>
                </div>
            </div>

            <!-- 部门负责人信息区 -->
            <div class="info-section" th:if="${department.departmentHead != null}">
                <h2 class="section-title">部门负责人</h2>
                <div class="info-grid">
                    <div class="info-item">
                        <span class="info-label">姓名：</span>
                        <span class="info-value" th:text="${department.departmentHead.realName}"></span>
                    </div>
                    <div class="info-item">
                        <span class="info-label">工号：</span>
                        <span class="info-value" th:text="${department.departmentHead.username}"></span>
                    </div>
                    <div class="info-item">
                        <span class="info-label">职位：</span>
                        <span class="info-value" th:text="${department.departmentHead.jobPosition?.positionName}"></span>
                    </div>
                </div>
            </div>

            <!-- 上级部门信息区 -->
            <div class="info-section" th:if="${department.parentDepartment != null}">
                <h2 class="section-title">上级部门</h2>
                <div class="info-grid">
                    <div class="info-item">
                        <span class="info-label">部门名称：</span>
                        <a th:href="@{/department/view/{id}(id=${department.parentDepartment.departmentID})}"
                           class="info-value link" th:text="${department.parentDepartment.departmentName}"></a>
                    </div>
                    <div class="info-item">
                        <span class="info-label">部门代码：</span>
                        <span class="info-value" th:text="${department.parentDepartment.departmentCode}"></span>
                    </div>
                </div>
            </div>

            <!-- 子部门信息区 -->
            <div class="info-section" th:if="${not #lists.isEmpty(department.subDepartments)}">
                <h2 class="section-title">子部门</h2>
                <div class="sub-department-list">
                    <div class="sub-department-item" th:each="subDept : ${department.subDepartments}">
                        <a th:href="@{/department/view/{id}(id=${subDept.departmentID})}"
                           class="sub-department-link" th:text="${subDept.departmentName}"></a>
                        <span class="sub-department-status"
                              th:classappend="${subDept.status} ? 'status-active' : 'status-inactive'"
                              th:text="${subDept.status} ? '启用' : '禁用'"></span>
                    </div>
                </div>
            </div>

            <!-- 部门介绍区 -->
            <div class="info-section" th:if="${department.departmentIntroduction != null}">
                <h2 class="section-title">部门介绍</h2>
                <div class="introduction-content" th:text="${department.departmentIntroduction}"></div>
            </div>

            <!-- 时间信息区 -->
            <div class="info-section">
                <h2 class="section-title">时间信息</h2>
                <div class="info-grid">
                    <div class="info-item">
                        <span class="info-label">创建时间：</span>
                        <span class="info-value" th:text="${department.createTime}"></span>
                    </div>
                    <div class="info-item" th:if="${department.updateTime != null}">
                        <span class="info-label">更新时间：</span>
                        <span class="info-value" th:text="${department.updateTime}"></span>
                    </div>
                </div>
            </div>
        </div>
    </main>
</div>
</body>
</html>